public class Ctrl_WorkOrderAttachment {
    public List<wrapAttachmentList> wrapList {get; set;}
    public String wId{get;set;}
    //public List<WorkOrder__c> wlist {get;set;}
	public string email{get;set;}
	public string head{get;set;}
	public string bbody{get;set;}
    public Ctrl_WorkOrderAttachment(ApexPages.StandardController con){
        if(wrapList == null) {
            wrapList = new List<wrapAttachmentList>();
            for(Attachment a: [SELECT id,Name,Body,ContentType from Attachment where parentid= : con.getId()]) {
                // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
                wrapList.add(new wrapAttachmentList(a));
            }
        }
        User us=[select Name,MobilePhone from User where id=:UserInfo.getUserId()] ;
        if(us.MobilePhone==null){us.MobilePhone='';}
        wId=con.getId();
        head='邮件主题';
        bbody='邮件正文 \n\n\n\n\n\n\n'+
        '*********************************************** \n'+
        us.Name+'\n'+us.MobilePhone+'\n'+
        '***********************************************';
        WorkOrder__c wo=[select id,Case__r.Contact.Email from WorkOrder__c where id=:con.getId()];
        email=wo.Case__r.Contact.Email; 
    }
    public PageReference back()
    {
    	PageReference retURL =new PageReference('/'+wId);
        return retURL;
    	
    }
    public void sendPdf()
	{
		Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
		         
		
		Messaging.EmailFileAttachment [] efaList = new  List<Messaging.EmailFileAttachment> () ;
		for(wrapAttachmentList at1:wrapList)
		{
		       if(at1.selected==true)
		       {
		       	   Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
				   efa.setFileName(at1.att.Name);
				   efa.setBody(at1.att.Body);
				   efa.setContentType(at1.att.ContentType);
				   efaList.add(efa) ;
		       }
		      
		 }
		 
		 if(efaList!=null)
		 {
		  	mail.setFileAttachments(efaList) ;
		 }
		 mail.setToAddresses(new String[] { email });  
		 mail.setSubject(head) ;   
		 mail.setCharset('UTF-8'); //Use Signatue
		 mail.setUseSignature(false);
		 mail.setPlainTextBody(bbody);
		 try{
		   
		   	Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
		 	ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,
                                     Label.Suc_SendAtt));
		 	
		 }catch(Exception e){
    		
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,
                                     Label.Err_EmailError+':'+e.getMessage()));
            
    	
		 }
	}
     
    public class wrapAttachmentList {
        public Attachment att {get; set;}
        public Boolean selected {get; set;}
 
        //This is the contructor method. When we create a new wrapAccount object we pass a Account that is set to the acc property. We also set the selected value to false
        public wrapAttachmentList(Attachment a) {
            att = a;
            selected = false;
        }
    }
}